<template>
	<u-popup v-model="iSelectPosterShow" mode="center" :mask-close-able="false">
		<view class="select-poster">
			<view class="close-btn" @click="$emit('close')">
				<u-icon name="close" size="36" />
			</view>
			<view class="select-poster-swiper">
				<u-swiper :list="posterTempFilePathList" :effect3d="true" height="846" :autoplay="false" mode="none"
					:current="current" :circular="false" @click="onClickSwiperItem" img-mode="widthFix" @change="swiperChange"></u-swiper>
			</view>
			<button class="save-btn" @click="save">
				保存图片
			</button>
		</view>
	</u-popup>
</template>

<script>
	export default {
		options: {
			styleIsolation: 'shared'
		},
		data() {
			return {
				list: [],
				current: 0,
			}
		},
		props: {
			iSelectPosterShow: {
				type: Boolean,
				default: false
			},
			posterTempFilePathList: {
				type: Array,
			}
		},
		watch: {
			iSelectPosterShow(val) {
				this.$emit('update:iSelectPosterShow', val);
			}
		},
		methods: {
			onClickSwiperItem(index) {
				this.current = index;
			},
			swiperChange(index){
				this.current = index;
			},
			save() {
				uni.saveImageToPhotosAlbum({
					filePath: this.posterTempFilePathList[this.current],
					success: () => {
						this.$showToast('保存成功');
						this.$emit('close');
					},
					// fail: () => {
					// 	this.$showToast('保存失败');
					// }
				});

			}
		}
	}
</script>

<style scoped lang="scss">
	@import "./selectPoster.scss";
</style>
